/********************************************************************************
* Description: 
* Author: hsqiang
* Create Date: 2023-06-22
********************************************************************************/
#ifndef EVENT_LOOP_POOL_HPP_
#define EVENT_LOOP_POOL_HPP_

#include "noncopyable.hpp"
#include "assert_define.hpp"
#include "event_loop.hpp"
#include <vector>

namespace event_framework
{
    class EventLoopPool;
    using SchedulerPolicy = std::function<EventLoop&(const EventLoopPool&)>;
    class EventLoopPool : Noncopyable
    {
    public:
        EventLoopPool(size_t sz) : pool(sz)
        {
            ASSERT(sz > 0);
            while (sz--)
            {
                pool.emplace_back();
            }
        }
        EventLoop& GetProperLoop()
        {
            ASSERT(schedulePolicy);
            return schedulePolicy(*this);
        }
        void SetSchedulerPolicy(SchedulerPolicy&& policy)
        {
            schedulePolicy = std::move(policy);
        }
    private:
        SchedulerPolicy schedulePolicy;
        std::vector<EventLoopPtr> pool;
    };
    using EventLoopPoolPtr = std::shared_ptr<EventLoopPool>;
}

#endif